#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'Perry'

#!/usr/bin/env python
from lib.format_time import *
from lib.HandleMysql import *
from lib.switch_code import *
from lib.handle_mongo import *

import sys
import datetime
reload(sys)
sys.setdefaultencoding('utf-8')


# Shop DBs
def set_db_emc_shop():
    conn = HandleMysql('shopemc-s.db.58dns.org','58885','shopemc58user','q5wtgdtbJvZSc2EQ','dbwww58com_shopemc')
    conn.connect()
    return conn

def set_db_emc_product():
    conn = HandleMysql('ecmproduct0-s.db.58dns.org', '58885', 'emcproduct_hprro', 'OqX1jJ3Qjy', 'dbwww58com_emcproduct_0')
    conn.connect()
    return conn

def set_db_emc_order():
    conn = HandleMysql('emcorder-s.db.58dns.org','58885','emcorder_hprro','Yb%LEfmLO5','dbwww58com_emcorder')
    conn.connect()
    return conn

def set_db_es_order():
    conn = HandleMysql('emcorder-s.db.58dns.org','58885','orderuser_fenxi','20KCM@GqxJ','dbwww58com_emcorder')
    conn.connect()
    return conn

def set_db_eapi():
    conn = HandleMysql('eapi-s.db.58dns.org','58885','user_api','X+N+=2j0$3epP0u','dbwww58com_api')
    conn.connect()
    return conn

# 58 VIP DBs
def set_db_enterprise():
    conn = HandleMysql('enterprise-s.db.58dns.org','58885','rdetda58user','A5doGsv8msxYF7dYVI','dbwww58com_enterprise')
    conn.connect()
    return conn

def set_db_boss():
    conn = HandleMysql('bossv10-s.db.58dns.org','58885','bossv58user','uKeBwzO9yQrReev','dbwww58com_bossv10')
    conn.connect()
    return conn

def set_visit_conn():
    conn = connect_db(host='bi02.service.58dns.org',db='iadvt_stat')
    return conn

def set_mdb_promotion_info():
    conn = connect_db(host='10.4.12.27',db='DBWWW58COM_PROMOTIONINFO',port='58017')
    return conn

def set_mdb_promotion_1():
    conn = connect_db(host='promotioninfo1.mdb.58dns.org',db='dbwww58com_promotion1',port='58885')
    return conn

def set_db_bsponline():
    conn = HandleMysql('bsponline-s.db.58dns.org','58885','rdda58user','QvShfxFgiXxbQ0r0ya','dbwww58com_bsponline')
    conn.connect()
    return conn

def set_db_jingjia_info():
    conn = HandleMysql('jingjiainfo-s.db.58dns.org','58885','jj58user_rd','cVJrlY8wcLlZdfgtt','dbwww58com_jingjiainfo')
    conn.connect()
    return conn

def set_db_product():
    conn = HandleMysql('productv3-s.db.58dns.org','58885','sjfxdbpv4_read','x$rfvsw2nhy67y&yy','dbwww58com_product_v4')
    conn.connect()
    return conn

def set_db_plibrarynew():
    conn = HandleMysql('plibrarynew-s.db.58dns.org','58885','rdpln58read','H5t8uV59niBZ5ABe5','dbwww58com_plibrarynew')
    conn.connect()
    return conn

# 58 Zhaopin DBs

def set_db_jianli():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment')
    conn.connect()
    return conn

def set_db_jianli01():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment0')
    conn.connect()
    return conn

def set_db_jianli02():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment1')
    conn.connect()
    return conn

def set_db_jianli03():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment2')
    conn.connect()
    return conn

def set_db_jianli04():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment3')
    conn.connect()
    return conn

def set_db_jianli05():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment4')
    conn.connect()
    return conn

def set_db_jianli06():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment5')
    conn.connect()
    return conn

def set_db_jianli07():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment6')
    conn.connect()
    return conn

def set_db_jianli08():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment7')
    conn.connect()
    return conn

def set_db_jianli09():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment8')
    conn.connect()
    return conn

def set_db_jianli10():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment9')
    conn.connect()
    return conn

def set_db_jianli11():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment10')
    conn.connect()
    return conn

def set_db_jianli12():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment11')
    conn.connect()
    return conn

def set_db_jianli13():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment12')
    conn.connect()
    return conn

def set_db_jianli14():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment13')
    conn.connect()
    return conn

def set_db_jianli15():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment14')
    conn.connect()
    return conn

def set_db_jianli16():
    conn = HandleMysql('recruitment-s.db.58dns.org','58885','export58user','UxkrTllu4QLbVu7T','DBWWW58COM_Recruitment15')
    conn.connect()
    return conn

# Groupbuy DBs

def set_db_groupbuy_kefu():
    conn = HandleMysql('grpbuycustomer-s.db.58dns.org','58885','user_customer','l@#jsaf(*safd1','dbwww58com_groupbuy_customer')
    conn.connect()
    return conn

def set_db_groupbuy_order():
    conn = HandleMysql('tgorder-s.db.58dns.org','58885','tg_order_ro','Jp8%$aNzXc&b','dbwww58com_groupbuy_v2')
    conn.connect()
    return conn

def set_db_groupbuy_master():
    conn = HandleMysql('tgorder-s.db.58dns.org','58885','groupbug_58bak','!@zVFKw##d865i','dbwww58com_groupbuy_v2')
    conn.connect()
    return conn

def set_db_groupbuy_slave():
    conn = HandleMysql('groupbuyv2-s.db.58dns.org','58885','user_fenxi','Jd&6&eJ8PR','dbwww58com_groupbuy_v2')
    conn.connect()
    return conn

# AD DBs

def set_db_ad_datacount():
    conn = HandleMysql('datacount.db.58dns.org','58885','rdtuanguser','d865lvfr4Rny&tt','dbwww58com_datacount')
    conn.connect()
    return conn

def set_db_ad_datacount_slave():
    conn = HandleMysql('datacount-s.db.58dns.org','58885','rdtuanguser','d865lvfr4Rny&tt','dbwww58com_datacount')
    conn.connect()
    return conn

def set_db_ad_newadvts():
    conn = HandleMysql('newadvts-s.db.58dns.org','58885','newas58user','cOA8tgbw7TpVxk6Ced','dbwww58com_newadvts')
    conn.connect()
    return conn

def set_db_ad_iadvt():
    """docstring for set_db_ad_iadvt"""
    conn = HandleMysql('eiadvt-s.db.58dns.org','58885','sjfx_rd','l2FGdq84yRt5L8w0Fn','dbwww58com_iadvt')
    conn.connect()
    return conn
    
def set_db_topinfo():
    """docstring for set_db_topinfo"""
    conn = HandleMysql('topinfo-s.db.58dns.org','58885','topolr58user','qy#u$#3sfuHn$qJe','dbwww58com_topinfo')
    conn.connect()
    return conn

    '''
    # AD DBs
    db_ad_iadvt=>['dbwww58com_iadvt','eiadvt.db.58dns.org','58885','sjfx_rd','l2FGdq84yRt5L8w0Fn'],
    db_58_top=>['dbwww58com_topinfo','topinfo-s.db.58dns.org','58885','topolr58user','qy#u$#3sfuHn$qJe'],
    db_bid_zhineng=>['dbwww58com_bidding_promotion','bidpromotion-s.db.58dns.org','58885','user_houpr_ro','iGpg3REtP@'],
    db_bid_promotion=>['dbwww58com_bidding_promotion','bidpromotion-s.db.58dns.org','58885','user_houpr_ro','iGpg3REtP@'],
    db_bid_stat=>['dbwww58com_bidding_stat','bidstat-s.db.58dns.org','58885','user_houpr_ro','iGpg3REtP@'],
    # Pay PMC DBs
    #db_pay_account_0=>['dbwww58com_pay_account_0','192.168.12.81','58885','syzn58user_rd','FwE6dfgtpas12t6m'],
    #db_pay_account_1=>['dbwww58com_pay_account_1','192.168.12.81','58885','syzn58user_rd','FwE6dfgtpas12t6m'],
    db_pay_account_0=>['dbwww58com_pay_account_new0','192.168.12.81','58885','syzn58user_rd','FwE6dfgtpas12t6m'],
    db_pay_account_1=>['dbwww58com_pay_account_new1','192.168.12.81','58885','syzn58user_rd','FwE6dfgtpas12t6m'],
    db_pay_account_2=>['dbwww58com_pay_account_new2','192.168.12.81','58886','syzn58user_rd','FwE6dfgtpas12t6m'],
    db_pay_account_3=>['dbwww58com_pay_account_new3','192.168.12.81','58886','syzn58user_rd','FwE6dfgtpas12t6m'],
    db_pay_order_0=>['dbwww58com_pay_order_0','192.168.12.81','58885','syzn58user_rd','FwE6dfgtpas12t6m'],
    db_pay_order_1=>['dbwww58com_pay_order_1','192.168.12.81','58885','syzn58user_rd','FwE6dfgtpas12t6m'],
    db_pay_order_2=>['dbwww58com_pay_order_2','192.168.12.81','58886','syzn58user_rd','FwE6dfgtpas12t6m'],
    db_pay_order_3=>['dbwww58com_pay_order_3','192.168.12.81','58886','syzn58user_rd','FwE6dfgtpas12t6m'],

    # Analysis DBs
    db_gb_stat=>['dbwww58com_groupbuy_stats','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_base_dict=>['dbwww58com_base_dicts','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_gb_open=>['dbwww58com_groupbuy_open','10.5.20.14','58885','ec_stat','L#c8UM5RGh5C'],
    db_58_ib=>['58','10.5.20.15','5029','root','group_buytj1140'],
    db_hy_stat=>['dbwww58com_huangye_stats','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_shop_stat=>['dbwww58com_shop_stats','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_pre_ads=>['dbwww58com_precision_ads','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_pa_stat=>['dbwww58com_precision_ads','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_api_stat=>['dbwww58com_api_stat','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_zp_stat=>['dbwww58com_zhaopin_stats','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_car_stat=>['dbwww58com_car_stats','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_58_stat=>['dbwww58com_58_stats','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_cron_tms=>['cronhub_manage_system','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_gb_ib=>['groupbuy','10.5.20.15','5029','root','group_buytj1140'],
    db_hy_ib=>['huangye','10.5.20.15','5029','root','group_buytj1140'],
    db_zp_ib=>['zhaopin','10.5.20.15','5029','root','group_buytj1140'],
    db_zhineng_ib=>['online_revenue','10.5.20.15','5029','root','group_buytj1140'],
    db_precise_ib=>['precise','10.5.20.15','5029','root','group_buytj1140'],
    db_jingjia_ib=>['jingjia','10.5.20.15','5029','root','group_buytj1140'],
    db_kezhan_stat=>['dbwww58com_kezhan_stats','10.5.20.16','58885','root','group_buytj1140'],
    #db_58_100=>['dbwww58com_portalnew','192.168.10.100','58885','roly58user','wsxedcrftfyE7I'],
    db_es_stat=>['dbwww58com_ershou_stats','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_58_stat=>['dbwww58com_58_stats','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_zhineng_stat=>['dbwww58com_online_revenue_stats','10.5.20.16','58885','ec_stat','L#c8UM5RGh5C'],
    db_58_crm=>['dbwww58com_crm','crm-s.db.58dns.org','58885','crm58user_rd','a9gbzuh9BJK4436'],
    db_wlt_info=>['dbwww58com_wltinfo','wltinfo-s.db.58dns.org','58885','wltinfo_read','t4rfRSc2tP5re45r'],
    '''
#mysql - stats
def set_stats_conn():
    conn = HandleMysql('10.3.10.50','58885','ec_stat','L#c8UM5RGh5C','dbwww58com_groupbuy_stats')
    conn.connect()
    return conn

#mysql - infobright
def set_ib_conn():
    conn = HandleMysql('10.3.13.27','5029','root','group_buytj1140','groupbuy')
    conn.connect()
    return conn

#mysql - cs
def set_cs_conn():
    conn = HandleMysql('192.168.10.81','58885','user_customer',"l@#jsaf(*safd1",'dbwww58com_groupbuy_customer')
    conn.connect()
    return conn

#logic
def execute(date):

    try:
        pass
    except Exception,e:
        print 'e:',e

#
def main():

   #date = '2012-05-28'
   #execute(date)
   if len(sys.argv)==1:
        start_date=get_yesterday()
        end_date=start_date
   elif len(sys.argv)==2:
        start_date=format_date(sys.argv[1])
        end_date=start_date
   elif len(sys.argv)==3:
        start_date=format_date(sys.argv[1])
        end_date=format_date(sys.argv[2])
   stat_date=start_date
   while stat_date>=start_date and stat_date<=end_date:
        print "The program of the date of %s is beginning at %s " %(stat_date,get_now())
        #
        execute( stat_date)
        print "The program of the date of %s is end at %s " %(stat_date,get_now())
        stat_date=var_date(stat_date)


if __name__=='__main__':
    main()
